﻿using System.ComponentModel;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using SX.BaseService.API.Base;
using SX.BaseService.Service;
using SX.BaseService.Service.Interface;
using SX.Core;

namespace SX.BaseService.API
{
   
    [Description("菜单管理")]
    [Menu]
    public class SysPermissionController : BaseController
    {
        private readonly ISysPermissionService _service;
        public SysPermissionController(ISysPermissionService sysPermissionService)
        {
            _service = sysPermissionService;
        }
       
        [HttpGet]
        [Description("查询菜单tree")]
        public async Task<IApiResult> GetTree()
        {
            return await _service.GetTree();
        }
       
        [HttpGet]
        [Description("菜单管理")]
        public async Task<IApiResult> Query([FromQuery]MenuQueryModel model)
        {
            return await _service.Query(model);
        }

        [HttpPost]
        [Description("新增")]
        public async Task<IApiResult> Add([FromBody]MenuAddModel model)
        {
            return await _service.Add(model);
        }
     
        [HttpPost]
        [Description("删除")]
        public async Task<IApiResult> Delete([FromBody]string id)
        {
            return await _service.Delete(id);
        }
       
        [HttpPost]
        [Description("更新")]
        public async Task<IApiResult> Update([FromBody] MenuUpdateModel model)
        {
            return await _service.Update(model);
        }

        /// <summary>
        /// 查询菜单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Description("详情")]
        public async Task<IApiResult> Get([FromQuery]string id)
        {
            return await _service.QueryById(id);
        }
       
        [HttpGet]
        [Description("排序")]
        public async Task<IApiResult> Sort([FromQuery]string parentId,string id,int flag)
        {
            return await _service.Sort(parentId,id,flag);
        }

    }
}